package service

import (
	"github.com/gin-gonic/gin"
	"go.uber.org/zap"
	"mts/log_srv/internal/domain"
	"mts/log_srv/internal/repository"
)

type LangService interface {
	FindLangByUserId(ctx *gin.Context, id string) (string, error)
	UpdateLangByUserId(ctx *gin.Context, lan domain.Language) error
}

type LangServiceImp struct {
	langRepo repository.LangRepo
}

func (s *LangServiceImp) UpdateLangByUserId(ctx *gin.Context, lan domain.Language) error {
	if err := s.langRepo.UpdateLangByUserId(ctx, lan); err != nil {
		zap.S().Errorf("获取日志失败:%s", err)
		return err
	}
	return nil
}

func (s *LangServiceImp) FindLangByUserId(ctx *gin.Context, id string) (string, error) {
	langId, err := s.langRepo.FindLangByUserId(ctx, id)
	if err != nil {
		zap.S().Errorf("获取日志失败:%s", err)
		return "", err
	}
	return langId, nil
}

func NewLangService(repo repository.LangRepo) LangService {
	return &LangServiceImp{
		langRepo: repo,
	}
}
